package ece.fr.varlet_aimez.multithread;

import java.util.Random;
import java.util.concurrent.Callable;

public class CallableThread implements Callable<Double>{

		private int nSteps, z,nbSimulationParThread;
		private double vSqrdt, S, Drift, X;
	
		/**
		 * 
		 * @param nSteps
		 * @param vSqrdt
		 * @param S
		 * @param Drift
		 * @param X
		 * @param z
		 * @param nbSimulationParThread
		 */
		public CallableThread(int nSteps,double vSqrdt, double S, double Drift, double X, int z, int nbSimulationParThread){
			this.nSteps=nSteps;
			this.vSqrdt=vSqrdt;
			this.S=S;
			this.Drift=Drift;
			this.X=X;
			this.z=z;
			this.nbSimulationParThread=nbSimulationParThread;
		}
		
		/**
		 * 
		 */
		public Double call() throws Exception {
			double sum=0.0; 
			for(int i=0;i<nbSimulationParThread;i++){
			  double St = S;
			  Random rand = new Random();
			  rand.setSeed(System.currentTimeMillis());
			  for (int j=0 ; j<nSteps ; j++) {
				  St = St * Math.exp(Drift + vSqrdt * rand.nextGaussian());
			  }
			  sum+=java.lang.Math.max(z*(St - X),0);
			  //System.out.println(Thread.currentThread().getName()+" sum : "+sum);
			}
	    	 return sum;
	      }
		
	}